package com.lighthouse.issue.base.controller;

import com.lighthouse.issue.base.domain.KnowledgeIssue;
import com.lighthouse.issue.base.service.IKnowledgeIssueService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 问题Controller
 * 
 * @author ysz
 * @date 2024-02-03
 */
@RestController
@RequestMapping("/knowledge/issue")
public class KnowledgeIssueController extends BaseController
{
    @Autowired
    private IKnowledgeIssueService knowledgeIssueService;

    /**
     * 查询问题列表
     */
    @PreAuthorize("@ss.hasPermi('knowledge:issue:list')")
    @GetMapping("/list")
    public TableDataInfo list(KnowledgeIssue knowledgeIssue)
    {
        startPage();
        List<KnowledgeIssue> list = knowledgeIssueService.selectKnowledgeIssueList(knowledgeIssue);
        return getDataTable(list);
    }

    /**
     * 导出问题列表
     */
    @PreAuthorize("@ss.hasPermi('knowledge:issue:export')")
    @Log(title = "问题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KnowledgeIssue knowledgeIssue)
    {
        List<KnowledgeIssue> list = knowledgeIssueService.selectKnowledgeIssueList(knowledgeIssue);
        ExcelUtil<KnowledgeIssue> util = new ExcelUtil<KnowledgeIssue>(KnowledgeIssue.class);
        util.exportExcel(response, list, "问题数据");
    }

    /**
     * 获取问题详细信息
     */
    @PreAuthorize("@ss.hasPermi('knowledge:issue:query')")
    @GetMapping(value = "/{issueId}")
    public AjaxResult getInfo(@PathVariable("issueId") Long issueId)
    {
        return success(knowledgeIssueService.selectKnowledgeIssueByIssueId(issueId));
    }

    /**
     * 新增问题
     */
    @PreAuthorize("@ss.hasPermi('knowledge:issue:add')")
    @Log(title = "问题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KnowledgeIssue knowledgeIssue)
    {
        return toAjax(knowledgeIssueService.insertKnowledgeIssue(knowledgeIssue));
    }

    /**
     * 修改问题
     */
    @PreAuthorize("@ss.hasPermi('knowledge:issue:edit')")
    @Log(title = "问题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KnowledgeIssue knowledgeIssue)
    {
        return toAjax(knowledgeIssueService.updateKnowledgeIssue(knowledgeIssue));
    }

    /**
     * 删除问题
     */
    @PreAuthorize("@ss.hasPermi('knowledge:issue:remove')")
    @Log(title = "问题", businessType = BusinessType.DELETE)
	@DeleteMapping("/{issueIds}")
    public AjaxResult remove(@PathVariable Long[] issueIds)
    {
        return toAjax(knowledgeIssueService.deleteKnowledgeIssueByIssueIds(issueIds));
    }
}
